<%@ Page Language="C#" MasterPageFile="~/Base.Master" AutoEventWireup="true" CodeBehind="Companies.aspx.cs" Inherits="SVAccountingWebUI.Companies" %>
<%@ MasterType VirtualPath="~/Base.Master" %>

<asp:Content ID="CompaniesContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
   
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CompanyID" 
        DataSourceID="CompaniesLinqDataSource" BackColor="White" 
        BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" 
        ForeColor="Black" GridLines="Vertical" 
        onrowcancelingedit="gv_RowCancelingEdit" 
        onrowdeleting="gv_RowDeleting" onrowediting="gv_RowEditing">
        <Columns>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, EditDelete %>">
                <EditItemTemplate>
                &nbsp;
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" ImageUrl="~/Icons/Update.png" Text="Update" />
                        /&nbsp;
                    <asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" ImageUrl="~/Icons/Cancel.png" Text="Cancel" />
                </EditItemTemplate>
                <ItemTemplate>
                &nbsp;
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" ImageUrl="~/Icons/Edit.png" Text="Edit" />
                    /&nbsp;<asp:ImageButton ID="DeleteButton" runat="server" CausesValidation="False" 
                        CommandName="Delete" ImageUrl="~/Icons/delete.png" Text="Delete"
                        message="<%$ Resources:Resource, DeleteConfirm %>" 
                        OnClientClick='return confirm(this.getAttribute("message"))'
                        />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="CompanyID" HeaderText="<%$ Resources:Resource, ID %>" 
                InsertVisible="False" ReadOnly="True" SortExpression="CompanyID" />
            <asp:BoundField DataField="CompanyName" HeaderText="<%$ Resources:Resource, Name %>" 
                SortExpression="CompanyName" />
            <asp:BoundField DataField="Address" HeaderText="<%$ Resources:Resource, Address %>" 
                SortExpression="Address" />
            <asp:BoundField DataField="Phone" HeaderText="<%$ Resources:Resource, Phone %>" SortExpression="Phone" />
            <asp:BoundField DataField="CreatedDate" HeaderText="<%$ Resources:Resource, CreatedDate %>" 
                SortExpression="CreatedDate" ReadOnly="True" />
            <asp:TemplateField SortExpression="EnrolmentType">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="EnrolmentTypesLinqDS" DataTextField="TypeCode" 
                        DataValueField="TypeCode" SelectedValue='<%# Bind("EnrolmentType") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <HeaderTemplate>
                    <asp:Label ID="Label6" runat="server" Text="<%$ Resources:Resource, EnrolmentType %>"></asp:Label>
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("EnrolmentType") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#CCCCCC" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#CCCCCC" />
    </asp:GridView>
   
    <asp:LinqDataSource ID="CompaniesLinqDataSource" runat="server" 
        ContextTypeName="SVAccountingBL.SVALinqDataContext" EnableDelete="True" 
        EnableInsert="True" EnableUpdate="True" TableName="Companies" 
        ondeleted="LinqDataSource_Deleted" 
        onupdated="LinqDataSource_Updated" 
        oninserted="LinqDataSource_Inserted" 
        oninserting="LinqDataSource_Inserting">
    </asp:LinqDataSource>
   
    <asp:LinqDataSource ID="EnrolmentTypesLinqDS" runat="server" 
        ContextTypeName="SVAccountingBL.SVALinqDataContext" Select="new (TypeCode)" 
        TableName="CompEnrolmentTypes">
    </asp:LinqDataSource>
   
   <asp:UpdatePanel ID="AddNewPanel" runat="server">
   <ContentTemplate>
    <br />
    <asp:LinkButton ID="lbtnAddNew" runat="server" 
                    Text="<%$ Resources:Resource, AddNew %>" 
           onclick="AddNew_Click"/>
    <br />
    <br />
   <div ID="InsertDiv" runat="server" visible="false">
    <asp:DetailsView ID="dvNewCompany" runat="server" AutoGenerateRows="False" 
        CellPadding="4" DataKeyNames="CompanyID" DataSourceID="CompaniesLinqDataSource" 
        ForeColor="#333333" GridLines="Vertical" Height="50px" Width="125px" DefaultMode="Insert" 
         onitemcommand="InsertDV_ItemCommand" EnableModelValidation="True">
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#C5BBAF" Font-Bold="True" />
        <RowStyle BackColor="#E3EAEB" />
        <FieldHeaderStyle BackColor="#D0D0D0" Font-Bold="True" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <Fields>
            <asp:BoundField DataField="CompanyID" HeaderText="CompanyID" 
                InsertVisible="False" ReadOnly="True" SortExpression="CompanyID" />
            <asp:TemplateField HeaderText="<%$ Resources:Resource, Name %>"  SortExpression="CompanyName">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CompanyName") %>' /> 
                </EditItemTemplate>
                <InsertItemTemplate>
                <table>
                <tr>
                    <td>
                    <asp:TextBox ID="txtCompanyName" runat="server" Text='<%# Bind("CompanyName") %>' />
                    </td>
                    <td>
                    <asp:RequiredFieldValidator ID="rfvCompanyName" runat="server" ErrorMessage="*" ControlToValidate="txtCompanyName" EnableClientScript="true" />
                    </td>
                </tr>
                </table>   
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("CompanyName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, Address %>" SortExpression="Address">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Address") %>' />
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Address") %>' />
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Address") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, Phone %>" SortExpression="Phone">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, CreatedDate %>" 
                SortExpression="CreatedDate" InsertVisible="False">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("CreatedDate") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("CreatedDate") %>' ReadOnly="true"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("CreatedDate") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, EnrolmentType %>" SortExpression="EnrolmentType">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("EnrolmentType") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" 
                        DataSourceID="EnrolmentTypesLinqDS" DataTextField="TypeCode" 
                        DataValueField="TypeCode" SelectedValue='<%# Bind("EnrolmentType") %>'>
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("EnrolmentType") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ButtonType="Image" CancelImageUrl="~/Icons/Cancel.png" 
                InsertImageUrl="~/Icons/Add.png" NewImageUrl="~/Icons/AddBig.png" 
                ShowInsertButton="True"  />
        </Fields>
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <InsertRowStyle BackColor="White" BorderColor="#999999" BorderStyle="Solid" 
            BorderWidth="1px" ForeColor="Black" />
        <EditRowStyle BackColor="#7C6F57" />
        <AlternatingRowStyle BackColor="White" />
    </asp:DetailsView>
    </div>
    </ContentTemplate>
    
    <Triggers>
         <asp:AsyncPostBackTrigger ControlID="lbtnAddNew" EventName="click" />
         <asp:PostBackTrigger ControlID="dvNewCompany" /> 
    </Triggers>
    
   </asp:UpdatePanel>
   
</asp:Content>